﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;
using System.IO;

namespace Com.CMS263.Web.manage.ProdAttr
{
    public partial class ModPa : System.Web.UI.Page
    {
        public int page = 1;
        string key;
        int id = 0;
        ProdTypeBLL ptbll = new ProdTypeBLL();
        public ProdType pt = new ProdType();
        protected void Page_Load(object sender, EventArgs e)
        {
            id = int.Parse(Request["id"]);
            page = string.IsNullOrEmpty(Request["page"]) ? 1 : int.Parse(Request["page"]);
            this.lbTypeName.Text ="商品类型" ;
            if (!Page.IsPostBack)
            {
                //根据父类类型盘点是否出默认结果
               
                if (id != 0)
                {
                    
                    pt = (ProdType)ptbll.FindModelById("ProdType",id);

                    if (pt.IsUse)
                    {
                        chkuse.Checked = true;
                    }
                    else
                    {
                        chkuse.Checked = false;
                    }
                    hdfTypeId.Value = id.ToString();
                }
                else
                {
                    hdfTypeId.Value = "0";
                    
                }
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int ptid = Convert.ToInt32(hdfTypeId.Value);
            if (ptid > 0)
            {
                ProdType ptt = new ProdType();
                ptt = (ProdType)ptbll.FindModelById("ProdType", ptid);
                string title = StringUtil.checkStr(Request["title"]);
                if (string.IsNullOrEmpty(title))
                {
                    StringUtil.Alert("请输入类型名称", "-1");
                }
                ptt.TypeName = title;
                if (chkuse.Checked)
                {
                    ptt.IsUse = true;
                }
                else
                {
                    ptt.IsUse = false;
                }
                ptbll.entity = ptt;
                ptbll.UpDate();
                StringUtil.Alert("修改成功", "PAList.aspx?page=" + page);
            }
            else
            {
                ProdType ptt = new ProdType();
                string title = StringUtil.checkStr(Request["title"]);
                if (string.IsNullOrEmpty(title))
                {
                    StringUtil.Alert("请输入类型名称", "-1");
                }
                ptt.TypeName = title;
                if (chkuse.Checked)
                {
                    ptt.IsUse = true;
                }
                else
                {
                    ptt.IsUse = false;
                }
                ptbll.entity = ptt;
                ptbll.Add();
                StringUtil.Alert("添加成功", "PAList.aspx");
            }
        }
    }
}
